package com.test.nnooolwdeaer.activity_fragment_wooden.loan_wooden;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;

import com.test.nnooolwdeaer.util_wooden.ThreadUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.DatePickeView_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.InputView_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.TitleView_wooden;
import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseLoanActivity_wooden;

import org.json.JSONObject;

//import co.paystack.android.Paystack;
//import co.paystack.android.PaystackSdk;
//import co.paystack.android.Transaction;
//import co.paystack.android.model.Card;
//import co.paystack.android.model.Charge;

public class AddPaystackBankAccountActivity_Niri_wooden extends BaseLoanActivity_wooden {

    private InputView_wooden bankAccountIv_wooden;
    private DatePickeView_wooden cardExpiresDpv_wooden;
    private InputView_wooden cvvIv_wooden;
    private Button addBtn_wooden;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_paystack_bank_account_wooden);
        init_wooden();
    }

    private void init_wooden(){
        TitleView_wooden titleView = findViewById(R.id.activity_add_paystack_bank_account_view_title);
        setBackBtn_wooden(titleView.getBackIb_wooden());

        bankAccountIv_wooden = findViewById(R.id.activity_add_paystack_bank_account_iv_bank_account);
        cardExpiresDpv_wooden = findViewById(R.id.activity_add_paystack_bank_account_dpv_card_expires);
        cvvIv_wooden = findViewById(R.id.activity_add_paystack_bank_account_iv_cvv);
        addBtn_wooden = findViewById(R.id.activity_add_paystack_bank_account_btn_add);

        addBtn_wooden.setOnClickListener(v -> {
            String bankAccount = bankAccountIv_wooden.getInput_wooden();
            String cardExpires = cardExpiresDpv_wooden.getInput_wooden();
            String cvv = cvvIv_wooden.getInput_wooden();
            if (TextUtils.isEmpty(bankAccount)||TextUtils.isEmpty(cardExpires)||TextUtils.isEmpty(cvv)){
                showToast_wooden(getString(R.string.word_input_tip));
                return;
            }
            String year = cardExpiresDpv_wooden.getYear_wooden();
            String month = cardExpiresDpv_wooden.getMonth_wooden();
            HttpManager_wooden.getInstance_wooden().orderRepaySDK_wooden(bankAccount, year, month, cvv);
        });

    }

    public void onOrderRepaySDKResponse_wooden(JSONObject jsonObject){
//        /*
//           accessCode: String,
//           pubKey: String
//         */
//        PaystackSdk.initialize(this);
//        String accessCode = jsonObject.optString("accessCode");
//        String pubKey = jsonObject.optString("pubKey");
//        if (TextUtils.isEmpty(accessCode) || TextUtils.isEmpty(pubKey)) {
//            showToast_wooden("Operation failed, please try again later.");
//            return;
//        }
//
//        String cardNumber = bankAccountIv_wooden.getInput_wooden();
//        String expiryYear = cardExpiresDpv_wooden.getYear_wooden();
//        String expiryMonth = cardExpiresDpv_wooden.getMonth_wooden();
//        String cvv = cvvIv_wooden.getInput_wooden();
//        Card card = new Card(cardNumber, Integer.parseInt(expiryMonth), Integer.parseInt(expiryYear), cvv);
////        if (!card.isValid()) {
////            showToast("Please enter the correct card number");
////            return;
////        }
//
//        Charge charge = new Charge();
//        charge.setCard(card);
//        charge.setAccessCode(accessCode);
//        PaystackSdk.setPublicKey(pubKey);
//        PaystackSdk.chargeCard(this, charge, new Paystack.TransactionCallback() {
//            @Override
//            public void onSuccess(Transaction transaction) {
//                showToast_wooden("Successful repayment");
//                ThreadUtil_wooden.getInstance_wooden().postDelay_wooden(() -> HttpManager_wooden.getInstance_wooden().requestUserProcess_wooden(), 1000);
//            }
//            @Override
//            public void beforeValidate(Transaction transaction) {}
//            @Override
//            public void onError(Throwable error, Transaction transaction) {
//                showToast_wooden(transaction.getReference());
//            }
//        });
    }
}